﻿using System;
using System.Collections.Generic;
using System.Text;

namespace YouHP.Utility
{
    public enum PageKeys
    {
        Unknown,

        User_LogCommentList,

        Profile_Index,

        Profile_CommentAdd,
        Profile_CommentList,

        Profile_ActionAdd,
        Profile_ActionList,

        Profile_FriendList,

        Profile_Log,
        Profile_LogList,
        Profile_LogCommentAdd,
        Profile_LogCommentList,
        Profile_GroupList,

        Profile_Condition,       //病情
    }

    public class PageHelper
    {
        private static Dictionary<string, PageKeys> PageIdentifyDict;
        private static Dictionary<string, PageKeys> CompactPageIdentifyDict;

        private static void InitPageIdentifyDict()
        {
            PageIdentifyDict = new Dictionary<string, PageKeys>();
            CompactPageIdentifyDict = new Dictionary<string, PageKeys>();

            CompactPageIdentifyDict.Add("/User/LogCommentList.aspx", PageKeys.User_LogCommentList);

            CompactPageIdentifyDict.Add("/Profile/Index.aspx", PageKeys.Profile_Index);
            CompactPageIdentifyDict.Add("/Profile/CommentList.aspx", PageKeys.Profile_CommentList);

            CompactPageIdentifyDict.Add("/Profile/Log.aspx", PageKeys.Profile_Log);
            CompactPageIdentifyDict.Add("/Profile/LogCommentList.aspx", PageKeys.Profile_LogCommentList);

            CompactPageIdentifyDict.Add("/Profile/LogList.aspx", PageKeys.Profile_LogList);
            CompactPageIdentifyDict.Add("/Profile/GroupList.aspx", PageKeys.Profile_GroupList);
        }

        public static PageKeys GetPageIdentify(string pagename)
        {
            if (PageIdentifyDict == null) InitPageIdentifyDict();

            if (PageIdentifyDict.ContainsKey(pagename)) return PageIdentifyDict[pagename];

            foreach (KeyValuePair<string, PageKeys> item in CompactPageIdentifyDict)
            {
                if (pagename.IndexOf(item.Key) > 0)
                {
                    PageIdentifyDict.Add(pagename, item.Value);
                    return item.Value;
                }
            }

            return PageKeys.Unknown;

        }

        public static PageKeys GetPageIdentify()
        {
            string url = RequestTools.GetAbsolutePath();
            return GetPageIdentify(url);
        }

        public static PageKeys GetReferrerPageIdentify()
        {
            string url = RequestTools.GetReferrerAbsolutePath();
            return GetPageIdentify(url);
        }
    }
}
